<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增顾客权益')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-equity-add">
            <input id="customerId" name="customerId" th:value="${customerId}"  type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">手机号：</label>
                <div class="col-sm-8">
                    <input name="phone" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">充电码：</label>
                <div class="col-sm-6">
                    <input name="code" id="code" class="form-control" type="text" required>
                </div>
                <div class="col-sm-2">
                    <button style="height: 31px;" th:onclick="'javascript:createCode()'" class="btn btn-success btn-xs " type="button">生成充电码</button>
                </div>
            </div>
<!--            <div class="form-group">    -->
<!--                <label class="col-sm-3 control-label">设备号：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <input name="sn" class="form-control" type="text" required>-->
<!--                </div>-->
<!--            </div>-->
            <div class="form-group">
                <input type="hidden"  id="showId" th:value="${showId}">
                <label class="col-sm-3 control-label">选择设备：</label>
                <div class="col-sm-8">
                    <select name="sn" id="sn" class="form-control m-b" th:with="type=${@udwl.getTableData('biz_device','device_code','name','enable')}" >
                        <option value="">请选择设备</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">端口号：</label>
                <div class="col-sm-8">
                    <input name="cargo" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">权益数：</label>
                <div class="col-sm-8">
                    <input name="equity" class="form-control" type="number" min="0" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">库存：</label>
                <div class="col-sm-8">
                    <input name="stock" class="form-control" type="number" min="0" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">位置：</label>
                <div class="col-sm-8">
                    <input name="position" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">来源：</label>
                <div class="col-sm-8">
                    <input name="source" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">启用状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('enableStatus')}">
                        <input type="radio" th:id="${'status_' + dict.dictCode}" name="status" th:value="${dict.dictValue}" th:checked="${dict.default}">
                        <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "biz/equity"
        $("#form-equity-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-equity-add').serialize());
            }
        }

        /**
         * 关闭订单
         * @param id
         */
        function createCode(){
            $.operate.get(prefix + "/create/code",function (result){
                console.log(result);
                if(result.code == 0){
                    $("#code").val(result.data);
                }
            })
        }
    </script>
</body>
</html>